<?php

if(!function_exists('setDonationAmounts')) {
    function setDonationAmounts(array $params, string $keyPrefix): array
    {
        $default_amount = [
            'short' => [20, 50, 100],
            'long'  => [20, 50, 100, 200, 500, 1000],
        ];

        $typeKey   = "{$keyPrefix}_donation_amount_type";
        $isShort   = ($params[$typeKey] ?? 0) == 0;
        $amountKey = "{$keyPrefix}_donation_amount_" . ($isShort ? '3' : '6');

        $userValues    = $params[$amountKey] ?? [];
        $defaultValues = $isShort ? $default_amount['short'] : $default_amount['long'];

        $finalValues = [];
        foreach ($defaultValues as $index => $default) {
            $value = $userValues[$index] ?? null;
            $finalValues[] = (trim((string)$value) !== '') ? $value : $default;
        }

        return $finalValues;
    }
}
